//
//  MyProgress.m
//  wobaifu
//
//  Created by hisuntech on 14-7-16.
//  Copyright (c) 2014年 hisuntech. All rights reserved.
//

#import "MyProgress.h"

@implementation MyProgress
@synthesize angle;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.angle = 1.0;
        
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

CGPoint firstCenter;
CGPoint secondCenter ;
-(void)Show
{
    [self.backProgressView.layer setMasksToBounds:YES];
    [self.backProgressView.layer setCornerRadius:10];//设置矩形四个圆角半径
    
    [self startAnimation2];
//    [self animationAction];
}

-(void)Hide
{
    [UIView animateWithDuration:0.3 animations:^{

    } completion:^(BOOL finished) {
        self.alpha=0;
        if (self.superview!=nil)
        {
            [self removeFromSuperview];
        }
    }];
}

bool firstBig=YES;

-(void)animationAction{
    [UIView animateWithDuration:0.1 animations:^{
    
//        self.iv_loading.transform = CGAffineTransformMakeRotation(degreesToRadian(angle));
        self.iv_loading.transform = CGAffineTransformMakeRotation(angle);
    } completion:^(BOOL finished)
     {
         angle++;
         [self performSelector:@selector(animationAction) withObject:nil afterDelay:0.05];
    }];
    
}

-(void)transformAction {
    angle = angle + 0.01;//angle角度 double angle;
    if (angle > 6.28) {//大于 M_PI*2(360度) 角度再次从0开始
        angle = 0;
    }
    CGAffineTransform transform=CGAffineTransformMakeRotation(angle);
    self.iv_loading.transform = transform;
}

-(void)startAnimation2{
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 0.7;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 100000;
    
    //    [self.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
    [self.iv_loading.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}



UIView *animationView;
-(void)addAnimationSubLayer:(UIView*)view{
    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.toValue = [NSNumber numberWithFloat:0.0];
    scaleAnimation.duration = 0.3;
    scaleAnimation.delegate = self;
    scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    
//    CAKeyframeAnimation *opacityAnimation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
//    opacityAnimation.duration = 0.3;
//    opacityAnimation.values = @[@0.45, @0.45, @0];
//    opacityAnimation.keyTimes = @[@0, @0.2, @1];
//    opacityAnimation.removedOnCompletion = NO;
//    
////    CAMediaTimingFunction *defaultCurve = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
//
//    CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
//    animationGroup.duration = 0.3;
//    animationGroup.autoreverses = YES;
//    animationGroup.repeatCount = 10000;
////    animationGroup.removedOnCompletion = NO;
////    animationGroup.timingFunction = defaultCurve;
//    animationGroup.delegate = self;
//    animationGroup.animations =[NSArray arrayWithObjects:scaleAnimation,opacityAnimation , nil];
//    [view.layer addAnimation:animationGroup forKey:@"animationGroup"];
    
    [view.layer addAnimation:scaleAnimation forKey:@"animationGroup"];
    animationView = view;
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
    NSLog(@"flag = %d",flag);
    NSLog(@"CAAnimation=%@",anim);
    if (flag) {
    
    }
}


@end
